<template>
  <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="200px"  class="demo-ruleForm">
    <el-form-item label="培训计划名称" prop="planName">
      <el-input v-model="ruleForm.planName" style="width: 300px"></el-input>
    </el-form-item>
    <el-form-item label="负责人" prop="principalName">
      <el-input v-model="ruleForm.principalName" style="width: 300px"></el-input>
    </el-form-item>
    <el-form-item label="计划简介" prop="planIntro">
      <el-input v-model="ruleForm.planIntro" style="width: 300px"></el-input>
    </el-form-item>
    <el-form-item label="培训课程选择" prop="courseSelect">
      <el-transfer
        filterable
        :filter-method="filterMethod"
        filter-placeholder="请输入课程名称或编码"
        v-model="value"
        :data="data"
        :titles="['待选课程','已选课程']">
      </el-transfer>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
      <el-button @click="resetForm('ruleForm')">重置</el-button>
    </el-form-item>
  </el-form>
</template>

<script>

  import { validateChinese, validatePhone} from "../../tools/validate";
    export default {

      name: "TrainPlanAdd",
      //生成未选择的数据
      data() {
        //穿梭框的数据项
        const generateData = _ => {
          const data = [];
          for (let i = 1; i <= 15; i++) {
            data.push({
              key: i,
              label: `课程- ${ i }`,
            });
          }
          return data;
        };

        return {
          //表单的各个数据项的值
          ruleForm: {
            planName:'',
            principalName:'',
            planIntro:'',

          },
          //穿梭框存放未选择的数据
          data: generateData(),
          //穿梭框存放选择课程的数据
          value:[],
          rules: {
            planName: [
              { required: true, message: '请输入计划名称', trigger: 'blur' },
              { min: 0, max: 15, message: '长度在 0 到 15 个字符', trigger: 'blur' },
            ],
            principalName: [
              { required: true, message: '请输入负责人名称', trigger: 'blur' },
              { min: 0, max: 8, message: '长度在 0 到 8 个字符', trigger: 'blur' },
              {validator:validateChinese,trigger: 'blur'}

            ],
            planIntro:[
              { required: true, message: '请输入负责人简介', trigger: 'blur' },
            ],
          },

        };
      },
      methods: {
        //表单提交
        submitForm(formName) {
          this.$refs[formName].validate((valid) => {
            if (valid) {
              alert('submit!');
            } else {
              console.log('error submit!!');
              return false;
            }
          });
        },
        //重置表单数据
        resetForm(formName) {
          this.$refs[formName].resetFields();
        },



      }
    }
</script>

<style scoped>

</style>
